<template>
	<mescroll-uni :ref="'mescrollRef'+i" @init="mescrollInit" @down="downCallback" @up="upCallback">
		<view style="padding: 0 40rpx;">
			<view v-for="(item, index) in dataList" :key="index" class="u-p-t-32 u-p-b-34 flex-center-between"
				style="border-bottom: 1rpx solid #EEEEEE">
				<view>
					<view class="u-f-32 u-lh-44 font-medio">{{ item.title || '' }}</view>
					<view class="u-m-t-6 u-f-24 u-lh-34 color-grew">{{ item.createTime || '' }}</view>
				</view>
				<view
					:class="['u-f-40 u-lh-48 font-bold', item.money > 0 ? 'color-green' : item.money < 0 ? 'color-red' : 'color-grew']">
					{{ `${ (item.money > 0 ? '+' : '') + (item.money  || 0) }` }}
				</view>
			</view>
		</view>
	</mescroll-uni>
</template>

<script>
	import {
		userUserReocrdPage
	} from '@/api/personal.js'
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/components/mescroll-uni/mixins/mescroll-more-item.js";

	export default {
		mixins: [MescrollMixin, MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
		props: {
			i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
			index: { // 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
				type: Number,
				default () {
					return 0
				}
			},
			coinType: {
				default: 1
			}
		},
		data() {
			return {
				dataList: []
			}
		},
		watch: {
			coinType: {
				handler(v) {
					this.downCallback()
				},
				deep: true,
				immediate: true
			}
		},
		methods: {
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				let node = this.$refs['mescrollRef' + this.i]
				userUserReocrdPage({
					pageNumber: page.num,
					pageSize: page.size,
					type: this.i,
					coinType: this.coinType
				}).then(res => {
					node && node.mescroll.endSuccess(res.list.length);
					if (page.num == 1) this.dataList = []; //如果是第一页需手动制空列表
					this.dataList = this.dataList.concat(res.list); //追加新数据
				}).catch(() => {
					node && node.mescroll.endErr();
				})
			},
			downCallback() {
				let node = this.$refs['mescrollRef' + this.i]
				node && node.mescroll.resetUpScroll()
			},
		}
	}
</script>
